package notYetUsed {
	import org.flixel.*;
	import entities.Player;
	
	
	/**
	 * This is a "moving platform" class, used to create moving walls and floors.
	 * It extends <code>FlxTileblock</code>.
	 */
	public class Moving extends FlxTileblock {
		private const moveLeft:int = -1;
		private const moveRight:uint = 1;
		private const moveUp:int = -1;
		private const moveDown:uint = 1;
		
		/**
		 * The starting position. (x, y) <br/>
		 * Access x and y individually with <code>startPnt.x</code> and <code>startPnt.y</code>.
		 */
		public var startPnt:FlxPoint;
		
		/**
		 * This is the distance to the LEFT of startPnt.<br/>
		 * (How far LEFT should it move from the starting point?)
		 */
		public var Left:Number = 20;
		/**
		 * This is the distance to the RIGHT of startPnt.<br/>
		 * (How far RIGHT should it move from the starting point?)
		 */
		public var Right:Number = 20;
		/**
		 * This is the distance UP from startPnt.<br/>
		 * (How far UP should it move from the starting point?)
		 */
		public var Up:Number = 20;
		/**
		 * This is the distance DOWN from startPnt.<br/>
		 * (How far DOWN should it move from the starting point?)
		 */
		public var Down:Number = 20;
		
		/**
		 * The horizontal(x) and vertical(y) speed.
		 * You will ALWAYS need to change at least one of these values.<br/>
		 *
		 * @default
		 * speedX	=	0 <br/>
		 * speedY	=	0
		 */
		public var speedXY:FlxPoint;
		
		private var directionXY:FlxPoint;
		private var minDist:FlxPoint;
		private var maxDist:FlxPoint;
		private var speedX:Number = 0;
		private var speedY:Number = 0;
		
		private var obj:FlxObject;
		private var player:Player = Registry.player;
		
		
		public function Moving(startX:Number, startY:Number, startDirection:String, Width:uint, Height:uint) {
			
			//ABSOLUTELY REQUIRED FIELDS
			super(startX, startY, Width, Height);
			
			switch (startDirection) {
				case "up":
					directionXY = new FlxPoint(0, moveUp);
					break;
				
				case "down":
					directionXY = new FlxPoint(0, moveDown);
					break;
				
				case "left":
					directionXY = new FlxPoint(moveLeft, 0);
					break;
				
				case "right":
					directionXY = new FlxPoint(moveRight, 0);
					break;
				
				case "up left":
					directionXY = new FlxPoint(moveLeft, moveUp);
					break;
				
				case "up right":
					directionXY = new FlxPoint(moveRight, moveUp);
					break;
				
				case "down left":
					directionXY = new FlxPoint(moveLeft, moveDown);
					break;
				
				case "down right":
					directionXY = new FlxPoint(moveRight, moveDown);
					break;
			}
			//End of ABSOLUTELY REQUIRED FIELDS
			
			startPnt = new FlxPoint(startX, startY);
			
			//use setBounds function to set the block's boundaries
			minDist = new FlxPoint(Left, Up);
			maxDist = new FlxPoint(Right, Down);
			
			//use setSpeed function to set the block's X and Y speed
			speedXY = new FlxPoint(speedX, speedY);
		}
		
		
		override public function update():void {
			super.update();
			/*
				//BOUND DEF - DEFINE WHAT HAPPENS WHEN THE BLOCK HITS ITS BOUNDARIES-=-=-
			
				//if x hits right bound, set x to right bound and flip x direction
				if(x - startPnt.x >= maxDist.x) {
					x = startPnt.x + maxDist.x;
					directionXY.x *= -1;
				}
					//else if x hits left bound, set x to left bound and flip x direction
				else if(x <= startPnt.x - minDist.x) {
					x = startPnt.x - minDist.x;
					directionXY.x *= -1;
				}
				//if y hits top bound, set y to top bound and flip y direction
				if(y <= startPnt.y - minDist.y) {
					y = startPnt.y - minDist.y;
					directionXY.y *= -1;
				}
					//else if y hits bottom bound, set y to bottom bound and flip y direction
				else if(y - startPnt.y >= maxDist.y) {
					y = startPnt.y + maxDist.y;
					directionXY.y *= -1;
				}
				//End BOUND DEF=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
			
				//ACTUALLY MOVE THE BLOCK
				x += directionXY.x * speedXY.x * FlxG.elapsed;
				y += directionXY.y * speedXY.y * FlxG.elapsed;
				//-----------------------
			
				for(var i:uint = 0; i < GameState._objects.members.length; i++) {
					obj = GameState._objects.members[i];
			
			
					var objMiddle:Number = obj.x + obj.origin.x; // X location of the object's center
			
					if(objMiddle >= this.left && objMiddle < this.right) {
						if(this.top - 0.5 <= obj.bottom && obj.bottom <= this.top) {
							obj.y = top - obj.height;
							obj.onFloor = true;
						}
					}
			
					if(obj.bottom - 1 >= this.top && obj.top + 2 <= this.bottom) {
						//if the object's right half is between block's left half, then obj.x = this.x - obj.width
						if(obj.right - 0.5 >= this.left && obj.x + obj.origin.x < x + this.origin.x)
							obj.x = this.x - obj.width;
							//else if object's left half is between block's right half, then object.x = this.right
						else if(obj.x + 0.5 <= this.right && obj.x + obj.origin.x > x + this.origin.x)
							obj.x = this.right;
					}
				}
			
			*/
			//EXECUTE ANY SPECIAL FUNCTIONS THAT WERE MADE IN customFunction()
			customFunction();
		
		
		}
		
		
		/**
		 * A more compact way of setting the boundaries that the block must stay within.
		 *
		 * @param	Left		How far left (from its initial position) should the block be allowed to move?
		 * @param	Right		How far right (from its initial position) should the block be allowed to move?
		 * @param	Up			How far up (from its initial position) should the block be allowed to move?
		 * @param	Down		How far down (from its initial position) should the block be allowed to move?
		 */
		public function setBounds(Left:Number, Right:Number, Up:Number, Down:Number):void {
			this.Left = Left;
			this.Right = Right;
			this.Up = Up;
			this.Down = Down;
			
			minDist = new FlxPoint(Left, Up);
			maxDist = new FlxPoint(Right, Down);
		}
		
		
		/**
		 * A more compact way of setting the horizontal and vertical speed.
		 *
		 * @param	speedX		The horizontal speed of the block.
		 * @param	speedY		The vertical speed of the block.
		 */
		public function setSpeed(speedX:Number, speedY:Number):void {
			speedXY.x = speedX;
			speedXY.y = speedY;
			
			speedXY = new FlxPoint(speedX, speedY);
		}
		
		
		//override
		public function hitTop(Contact:FlxObject, Velocity:Number):void {
		/*
		for(var i:uint = 0; i < GameState._objects.members.length; i++) {
			obj = GameState._objects.members[i];
		
			if(Contact == obj) {
				obj.x += directionXY.x * speedXY.x * FlxG.elapsed;
				obj.y += directionXY.y * speedXY.y * FlxG.elapsed;
			}
		}
		
		return super.hitTop(Contact, Velocity);
		*/
		}
		
		
		private function customFunction():void {
			//Whatever you want!
		}
	}
}
